#include <cstdio>
#include <string>
#include <vector>
#include <iostream>
using namespace std;

const int maxn = 30;
int n;
vector<int>pile[maxn];

void find_block(int a,int& p,int& h)
{
	for(p = 0;p < n;p++)
		for(h = 0;h < pile[p].size();h++)
			if(pile[p][h] == a)		return;
}
void clear_above(int p,int h)
{
	
}
void pile_onto(int p,int h,int p2)
{
	
}
void print()
{
	
}
int main()
{
	int a,b;
	cin >> n;
	string s1,s2;
	for(int i=0;i < n;i++) 		pile[i].push_back(i);
	while(cin >> s1 >> a >> s2 >> b){
		int pa,pb,ha,hb;
		find_block(a,pa,ha);
		find_block(b,pb,hb);
		if(pa == pb) continue;
		if(s2 == "onto") clear_above(pb,hb);
		if(s1 == "move") clear_above(pa,ha);
		pile_onto(pa,ha,pb);
	}
	print();
	return 0;
}

